package Injector

import "reflect"

type BeanMapper map[reflect.Type]reflect.Value

func (m BeanMapper) add(v interface{}) {
	t := reflect.TypeOf(v)
	if t.Kind() != reflect.Ptr {
		panic("必须是指针类型")
	}
	m[t] = reflect.ValueOf(v)
}

func (m BeanMapper) get(v interface{}) reflect.Value {
	var vtype reflect.Type
	//断言是 反射type类型
	if val, ok := v.(reflect.Type); ok {
		vtype = val
	} else {
		//非反射类型 获取
		vtype = reflect.TypeOf(v)
	}
	//判断是否存在
	if val, ok := m[vtype]; ok {
		return val
	}
	//返回空
	return reflect.Value{}
}
